package com.ruoyi.system.web.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.system.domain.dto.CarsDto;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.Cars;
import com.ruoyi.system.service.ICarsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 汽车管理Controller
 *
 * @author ruoyi
 * @date 2023-05-10
 */
@RestController
@RequestMapping("/system/cars")
public class CarsController extends BaseController {
    @Autowired
    private ICarsService carsService;

    /**
     * 查询汽车管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:cars:list')")
    @GetMapping("/list")
    public TableDataInfo list(Cars cars) {
        startPage();
        List<Cars> list = carsService.selectCarsList(cars);
        return getDataTable(list);
    }

    /**
     * 导出汽车管理列表
     */
    @PreAuthorize("@ss.hasPermi('system:cars:export')")
    @Log(title = "汽车管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Cars cars) {
        List<Cars> list = carsService.selectCarsList(cars);
        ExcelUtil<Cars> util = new ExcelUtil<Cars>(Cars.class);
        util.exportExcel(response, list, "汽车管理数据");
    }

    /**
     * 获取汽车管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:cars:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(carsService.selectCarsById(id));
    }

    /**
     * 新增汽车管理
     */
    @PreAuthorize("@ss.hasPermi('system:cars:add')")
    @Log(title = "汽车管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarsDto carsDto) {
        return toAjax(carsService.insertCars(carsDto));
    }

    /**
     * 修改汽车管理
     */
    @PreAuthorize("@ss.hasPermi('system:cars:edit')")
    @Log(title = "汽车管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Cars cars) {
        return toAjax(carsService.updateCars(cars));
    }

    /**
     * 删除汽车管理
     */
    @PreAuthorize("@ss.hasPermi('system:cars:remove')")
    @Log(title = "汽车管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(carsService.deleteCarsByIds(ids));
    }
}
